<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>51问医生</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <script src="{{url('/js/jquery.min.js')}}" type="text/javascript"></script>
    <link rel="stylesheet" href="{{url('new/css/common.css')}}" />

    <script src="{{url('new/js/doctor_list.js')}}"></script>
    <link rel="stylesheet" href="{{url('new/css/usercenter-set.css')}}" />

    <link rel="stylesheet" href="{{url('/css/foxui.css')}}">
    <link rel="stylesheet" href="{{url('/css/foxui.theme.css')}}">
    <script type="text/javascript" src="{{url('js/foxui.js')}}"></script>

    <!-- Plupload上传类 -->
    <script src="{{ url('vendor/plupload-2.1.2/plupload.full.min.js') }}"></script>
    <script src="{{ url('vendor/plupload-2.1.2/i18n/zh_CN.js') }}"></script>

    <!-- Noty 提示框的js集成 -->
    <script src="{{ url('vendor/noty-2.2.9/packaged/jquery.noty.packaged.js') }}"></script>
    <script src="{{ url('vendor/noty-2.2.9/themes/bootstrap.js') }}"></script>
    <script src="{{ url('vendor/noty-2.2.9/options.js') }}"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <style>
        .card {
            padding: .213333333333333rem 4.266666666666667%;
            background: #fff;
            overflow: hidden;
            margin-bottom: .213333333333333rem;
        }
        .ax-boxshadow {
            box-shadow: 1px 1px 1px 0 rgba(0,0,0,.1);
        }
        .card .card-img {
            width: 1.6rem;
            height: 1.6rem;
            border-radius: 50%;
            float: left;
            margin-left: 20px;
        }
        .card .card-img img {
            width: 100%;
            height: 100%;
        }
        .card .card-right {
            float: left;
            margin-left: .426666666666667rem;
            margin-top: 10px;
        }
        .card .card-right .photo {
            font-size: .373333333333333rem;
            padding: 0 .213333333333333rem;
            color: #f57c00;
            line-height: .746666666666667rem;
            border: 1px solid rgba(0,0,0,.15);
            border-radius: 1.333333333333333rem;
            background: #fbfafc;
        }
        .jianjie{
            width: 270px;
            height: 85px;
            /* right: 0px; */
            float: right;
            margin-top: 8px;
            border: 1px solid #bababa;
            border-radius: 5px 5px 5px 5px
        }
        .sel_hospital{
            width: 200px;
            height: 28px;
            margin-left: 10px;
            border: 1px solid #bababa;
        }
    </style>
</head>
<body>
<div class="register">
    <div class="card ax-boxshadow">
        <div class="card-img">
            <img id="photoShow" src="@if($userinfo){{route('Api.Image.Show',['id'=>$userinfo->doc_img])}}@else{{route('Api.Image.Show',['id'=>0])}}@endif" />
        </div>
        <p class="card-right">
            <span class="photo" id="uploadphoto">点击设置头像</span>
            <input type="hidden" id="photoId" value="@if($userinfo){{$userinfo->doc_img}}@endif" />
        </p>
    </div>
    <div class="reg-port">
        <span class="lable">姓名</span>
        <input type="text" id="realname" value="@if($userinfo){{$userinfo->doc_name}}@endif" placeholder="请输入真实姓名（必填）" />
        <span class="svgclear" ></span>
    </div>

    <div class="reg-port">
        <span class="lable">性别</span>
            <select id="sex" class="sel_hospital">
                <option value="1" @if($userinfo && $userinfo->sexual == 1)selected @endif>男</option>
                <option value="0" @if($userinfo && $userinfo->sexual == 0)selected @endif>女</option>
            </select>
        <span class="svgclear" ></span>
    </div>

    <div class="reg-port">
        <span class="lable">医院</span>
        <select class="sel_hospital" id="hospital">
            <option value="">请选择所属医院（必选）</option>
            @foreach($hospitals as $hospital)
            <option value="{{$hospital->id}}" @if($userinfo && $userinfo->hospital_id == $hospital->id)selected @endif>{{$hospital->name}}</option>
                @endforeach
        </select>
        <span class="svgclear" ></span>
    </div>
    <div class="reg-port">
        <span class="lable">科室</span>
        <select id="dep_list" class="sel_hospital">
            <option value="0">请选择科室</option>
            @foreach($deps as $dep)
                <option value="{{$dep->id}}" @if($userinfo && $dep->id == $userinfo->dep_id)selected @endif>{{$dep->dep_name}}</option>
            @endforeach
        </select>
        <span class="svgclear" ></span>
    </div>
    <div class="reg-port">
        <span class="lable">职称</span>
        <select class="sel_hospital" name="station" id="doc_type">
            <option value="主任医生" @if($userinfo && $userinfo->station == '主任医生')selected @endif>主任医生</option>
            <option value="副主任医生" @if($userinfo && $userinfo->station == '副主任医生')selected @endif>副主任医生</option>
            <option value="主治医生" @if($userinfo && $userinfo->station == '主治医生')selected @endif>主治医生</option>
        </select>
        <span class="svgclear" ></span>
    </div>
    <div class="reg-port">
        <span class="lable">费用</span>
        <input type="text" id="fee" value="@if($userinfo){{$userinfo->fee}}@endif" placeholder="请输入预约费用（必填）" />
        <span class="svgclear" ></span>
    </div>
    <div class="reg-port">
        <span class="lable">手机</span>
        <input type="text" id="phone" value="@if($userinfo){{$userinfo->phone}}@endif" placeholder="请输入手机号（必填）" />
        <span class="svgclear" ></span>
    </div>
    <div class="reg-port" style="height: 100px;">
        <span class="lable">简介</span>
        <span>
            <textarea class="jianjie" id="introduction">@if($userinfo){{$userinfo->introduction}}@endif</textarea>
        </span>
        <span class="svgclear" ></span>
    </div>
    <div class="reg-port">
        <span class="lable">公告</span>
        <input type="text" id="notice" value="@if($userinfo){{$userinfo->notice}}@endif" placeholder="请输入您的公告" />
        <span class="svgclear" ></span>
    </div>
    {{--<div class="reg-port">--}}
        {{--<span class="lable">证书</span>--}}
        {{--<input type="button" id="diplomaUp" value="@if(!$userinfo || ($userinfo && $userinfo->diploma_id == 0))点击上传您的证书@else已存在证书，可重新上传 @endif" />--}}
        {{--<input type="hidden" id="diploma_id" value="@if($userinfo){{$userinfo->diploma_id}}@endif" />--}}
        {{--<span class="svgclear" ></span>--}}
    {{--</div>--}}
    <a href="javascript:;">
        <div class="btn-submit  ax-bareBtn ">
            <input type="hidden" id="doc_id" value="@if($userinfo){{$userinfo->id}}@endif">
            <button type="submit" id="btn_send">
                <i class="ax-pay-loading"></i>
                提交
            </button>
        </div>
    </a>
</div>
<script>
    $(function(){
        var url=location.href;
        $.ajax({
            type : "post",
            url : "{{url('api/wechat/get-js-api-packet')}}",//替换网址，xxx根据自己jssdk文件位置修改
            dataType : "json",
            data:{url:url},
            success : function(obj){
                if(obj.level == 'success'){
                    var data = obj.data;
                    wx.config({
                        appId: data.appId,
                        timestamp: data.timestamp,
                        nonceStr: data.nonceStr,
                        signature: data.signature,
                        jsApiList: [
                            "onMenuShareTimeline", //分享给好友
                            "onMenuShareAppMessage", //分享到朋友圈
                            "onMenuShareQQ", //分享到QQ
                            "onMenuShareWeibo", //分享到微博
                            'chooseImage', 'previewImage', 'uploadImage', 'downloadImage'
                        ]
                    });
                }
            },
            error:function(data){
                alert("连接失败！");
            }
        });

        $('#uploadphoto').click(function () {
            wx.chooseImage({
                count: 1,
                sizeType: ['original', 'compressed'],
                sourceType: ['album', 'camera'],
                success: function(res) {
                    var localIds = res.localIds;
                    $('#photoShow').attr('src',localIds[0]);
                    uploadImg(localIds[0]);
                }
            });
        });

        var imgServerId = '';
        function uploadImg(localId) {
            wx.uploadImage({
                localId: localId, // 需要上传的图片的本地ID，由chooseImage接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function(res) {
                    imgServerId = res.serverId; // 返回图片的服务器端ID
                }
            });
        }


        $('#btn_send').click(function(){
            var photoId  = $('#photoId').val();
            var realname = $('#realname').val();
            var hospital = $('#hospital').val();
            var phone    = $('#phone').val();
            var depList  = $('#dep_list option:selected').val();
            var station  = $('#doc_type option:selected').val();
            var introduction = $('#introduction').val();
            var sex      = $('#sex option:selected').val();
            var notice   = $('#notice').val();
            var fee      = $('#fee').val();
//            var diploma_id = $('#diploma_id').val();
            var doc_id = $('#doc_id').val();

            if(realname.trim().length == 0){
                noty({'type':'error','text':'请输入真实姓名',timeout:600});
                $('#realname').focus();
                return ;
            }

            if(phone.trim().length == 0){
                noty({'type':'error','text':'请输入手机号',timeout:600});
                $('#phone').focus();
                return ;
            }

            if(station.trim().length == 0){
                noty({'type':'error','text':'请输入您的职称',timeout:600});
                $('#station').focus();
                return ;
            }

            if(hospital.trim().length == 0){
                noty({'type':'error','text':'请输入选择您所在的医院',timeout:600});
                return ;
            }

            if(introduction.trim().length == 0){
                noty({'type':'error','text':'请输入您的简介',timeout:600});
                $('#introduction').focus();
                return ;
            }
            $.ajax({
                type:"post",
                url:'{{route('Api.Doctor.setUserInfo')}}',
                dataType:"json",
                data:{
                    "name":realname,
                    "photo":photoId,
                    "dep_list":depList,
                    "station":station,
                    "introduction":introduction,
                    'fee':fee,
                    "hospital_id":hospital,
                    'phone':phone,
                    "notice":notice,
                    'sex':sex,
                    'id':doc_id,
                    'wx_photo':imgServerId
                },
                success:function(obj){
                    if(obj.level == "success"){
                        noty({text:obj.message,type:obj.level,timeout:600,
                            callback:{
                                afterClose:function(){
                                    window.location.href="{{route('M.Doctor.userCenter')}}";
                                }
                            }
                        });
                    }else{
                        noty({'type':'error','text':obj.message,timeout:600});
                    }
                },
                error:function(obj){
                    var datajson = obj.responseJSON;
                    FoxUI.alert(datajson.message,'提示语');
                }
            });
        });

        $('#doc_type').change(function() {
            var selectValue = $(this).children('option:selected').val();
            if(selectValue == "主任医生" || selectValue == "副主任医生"){
                $('#fee').val(7);
            }else if(selectValue == "主治医生"){
                $('#fee').val(4);
            }
        });

        jQuery.ajaxSetup({
            case:false,
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        <!-- 医院联动查询 -->
        $('#hospital').change(function(){
            var id = $('#hospital option:selected').val();
            if(parseInt(id) != 0){
                $.ajax({
                    url:"{{route('Api.Doctor.getDepartmentByHospitalId')}}?id="+id,
                    type:"get",
                    dataType:"json",
                    success:function (obj) {
                        if(obj.level == 'success'){
                            appendDepartmen(obj.data);
                        }else {
                            noty({'type':'error','text':obj.message,timeout:600});
                        }
                    },
                    error:function (obj) {
                        console.log(obj);
                    }
                });
            }
        });

        //写入部门
        function appendDepartmen(data) {
            $('#dep_list').empty();
            if(data.length > 0){
                for(var i = 0;i < data.length;i++){
                    var htmlElent = '<option value="'+data[i].id+'">'+data[i].dep_name+'</option>';
                    $('#dep_list').append(htmlElent);
                }
            }else {
                $('#dep_list').append('<option value="0" selected>请选择科室</option>');
            }
        }

        //上传头像
        {{--var uploader = new plupload.Uploader({--}}
            {{--runtimes: 'html5,flash,silverlight,html4',--}}
            {{--browse_button: 'uploadphoto',--}}
            {{--url: '{{route('Api.Upload.Image')}}',--}}

            {{--chunk_size: '20mb',--}}
            {{--filters: {--}}
                {{--max_file_size: '10mb',--}}
                {{--mime_types: [--}}
                    {{--{title: "Image files", extensions: "jpg,gif,png,jpeg"}--}}
                {{--],--}}
                {{--prevent_duplicates: false--}}
            {{--},--}}
            {{--multi_selection: true,--}}
            {{--unique_names: true,--}}

            {{--flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',--}}
            {{--silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',--}}

            {{--file_data_name: 'photo',--}}
            {{--headers: {--}}
                {{--Accept: 'application/json'--}}
            {{--},--}}

            {{--multipart_params: {--}}
                {{--_token: '{{ csrf_token() }}'--}}
            {{--},--}}

            {{--init: {--}}
                {{--PostInit: function () {--}}
                {{--},--}}

                {{--FilesAdded: function (up, files) {--}}
                    {{--up.start();--}}
                {{--},--}}

                {{--BeforeUpload: function (up, file) {--}}
                    {{--up.settings.multipart_params.file_name = file.name;--}}
                {{--},--}}

                {{--UploadProgress: function (up, file) {--}}
                    {{--$('#uploadphoto').html('上传中...');--}}
                {{--},--}}

                {{--Error: function (up, err) {--}}
                    {{--var responseObj = '', responseMessage = '';--}}
                    {{--try {--}}
                        {{--responseObj = $.parseJSON(err.response);--}}
                        {{--responseMessage = responseObj.message;--}}
                    {{--} catch ($e) {--}}

                    {{--}--}}

                    {{--noty({--}}
                        {{--type: 'error',--}}
                        {{--text: err.message + ' ' + responseMessage,--}}
                        {{--timeout: 800--}}
                    {{--});--}}
                {{--},--}}

                {{--FileUploaded: function (up, file, info) {--}}
                    {{--var responseObj = '', responseMessage = '';--}}
                    {{--try {--}}
                        {{--responseObj = $.parseJSON(info.response);--}}
                        {{--responseMessage = responseObj.message;--}}
                    {{--} catch ($e) {--}}

                    {{--}--}}
                    {{--$('#photoId').val(responseObj.data.id);--}}
                    {{--$url = "{{route('Api.Image.Show',['id'=>''])}}/"+responseObj.data.id;--}}
                    {{--$url = $url + "?" + Math.random();--}}
                    {{--$('#photoShow').attr('src',$url);--}}
                    {{--$('#uploadphoto').html('点击重新上传头像');--}}
                {{--}--}}
            {{--}--}}
        {{--});--}}
        {{--uploader.init();--}}

        //上传证书
        {{--var uploader2 = new plupload.Uploader({--}}
            {{--runtimes: 'html5,flash,silverlight,html4',--}}
            {{--browse_button: 'diplomaUp',--}}
            {{--url: '{{route('Api.Upload.Image')}}',--}}

            {{--chunk_size: '20mb',--}}
            {{--filters: {--}}
                {{--max_file_size: '10mb',--}}
                {{--mime_types: [--}}
                    {{--{title: "Image files", extensions: "jpg,gif,png"}--}}
                {{--],--}}
                {{--prevent_duplicates: false--}}
            {{--},--}}
            {{--multi_selection: true,--}}
            {{--unique_names: true,--}}

            {{--flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',--}}
            {{--silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',--}}

            {{--file_data_name: 'photo',--}}
            {{--headers: {--}}
                {{--Accept: 'application/json'--}}
            {{--},--}}

            {{--multipart_params: {--}}
                {{--_token: '{{ csrf_token() }}'--}}
            {{--},--}}

            {{--init: {--}}
                {{--PostInit: function () {--}}
                {{--},--}}

                {{--FilesAdded: function (up, files) {--}}
                    {{--up.start();--}}
                {{--},--}}

                {{--BeforeUpload: function (up, file) {--}}
                    {{--up.settings.multipart_params.file_name = file.name;--}}
                {{--},--}}

                {{--UploadProgress: function (up, file) {--}}
                    {{--$('#diplomaUp').val('上传中...');--}}
                {{--},--}}

                {{--Error: function (up, err) {--}}
                    {{--var responseObj = '', responseMessage = '';--}}
                    {{--try {--}}
                        {{--responseObj = $.parseJSON(err.response);--}}
                        {{--responseMessage = responseObj.message;--}}
                    {{--} catch ($e) {--}}

                    {{--}--}}

                    {{--noty({--}}
                        {{--type: 'error',--}}
                        {{--text: err.message + ' ' + responseMessage,--}}
                        {{--timeout: 800--}}
                    {{--});--}}
                {{--},--}}

                {{--FileUploaded: function (up, file, info) {--}}
                    {{--var responseObj = '', responseMessage = '';--}}
                    {{--try {--}}
                        {{--responseObj = $.parseJSON(info.response);--}}
                        {{--responseMessage = responseObj.message;--}}
                    {{--} catch ($e) {--}}

                    {{--}--}}
                    {{--$('#diploma_id').val(responseObj.data.id);--}}
                    {{--$('#diplomaUp').val('上传成功');--}}
                {{--}--}}
            {{--}--}}
        {{--});--}}
        {{--uploader2.init();--}}
    });
</script>
</body>
</html>